#ifndef __GOBANG_H__
#define __GOBANG_H__

#include "WhitePlayer.hpp"
#include "BlackPlayer.hpp"
#include "KeyHandle.hpp"
#include "Judge.hpp"
#include "WinLogo.hpp"

class Gobang
{
public:
	Gobang(const string& blackPlayer, const string& whitePlayer)
	{
		// 初始化棋手
		players[0] = new WhitePlayer(whitePlayer);
		players[1] = new BlackPlayer(blackPlayer);

		// 显示棋盘
		ChessBoard* chessBoard = ChessBoard::getChessBoard();
		chessBoard->show();

		keyHandle = new KeyHandle;
	}

	~Gobang()
	{
		delete players[0];
		delete players[1];
		delete keyHandle;
	}

	void run()
	{
		bool gameOver = false;

		while (!gameOver)
		{
			for (Player* player : players)
			{
				keyHandle->waitPlayerPlaceChess(player);
				bool win = judge.isWin(player);
				if (win)
				{
					gameOver = true;
					logo.showWinPlayer(player->getName(), player->getColor());
					break;
				}
			}
		}
	}
private:
	Player* players[2];
	KeyHandle *keyHandle;
	Judge judge;
	WinLogo logo;
};

#endif // !__GOBANG_H__
